<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1 id="h1box"></h1>
    <script>
         function addZero(n){
            return n>9 ? n : "0"+n;
         }

         function clock(){
            var date=new Date();
            var year=date.getFullYear();//年
            var month=date.getMonth()+1;//月
            var datee=date.getDate();//日
            var day=date.getDay();//周 0
            var weekarr=["周日","周一","周二","周三","周四","周五","周六"];
            var hours=date.getHours();//时
            var minutes=date.getMinutes();//分
            var seconds=date.getSeconds();//秒

            var str=`${year}年${addZero(month)}月${addZero(datee)}日${weekarr[day]}${addZero(hours)}时${addZero(minutes)}分${addZero(seconds)}秒`;
            
            return str;
         }
        
         //一打开页面的时候，立刻取时间
         h1box.innerHTML=clock();
        
         var timer=null;
         //每个1000毫秒取一次时间
         timer=setInterval(()=>{
            h1box.innerHTML=clock();
         },1000)

    </script>
</body>
</html>